package org.dromara.system.controller.api;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.system.api.domain.bo.RemoteSocialBo;
import org.dromara.system.api.domain.vo.RemoteSocialVo;
import org.dromara.system.domain.bo.SysSocialBo;
import org.dromara.system.domain.vo.SysSocialVo;
import org.dromara.system.service.ISysSocialService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:31
 * @version: v1
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/system/social")
public class SysSocialApiController {

    private final ISysSocialService sysSocialService;

    /**
     * 根据 authId 查询用户授权信息
     *
     * @param authId 认证id
     * @return 授权信息
     */
    @GetMapping("/by/authId")
    public R<List<RemoteSocialVo>> selectByAuthId(@RequestParam("authId") String authId) {
        List<SysSocialVo> list = sysSocialService.selectByAuthId(authId);
        return R.ok(MapstructUtils.convert(list, RemoteSocialVo.class));
    }

    /**
     * 查询列表
     *
     * @param remoteSocialBo 社会化关系业务对象
     */
    @PostMapping("/list")
    public R<List<RemoteSocialVo>> querySocialList(@RequestBody RemoteSocialBo remoteSocialBo) {
        SysSocialBo params = MapstructUtils.convert(remoteSocialBo, SysSocialBo.class);
        List<SysSocialVo> list = sysSocialService.queryList(params);
        return R.ok(MapstructUtils.convert(list, RemoteSocialVo.class));
    }

    /**
     * 保存社会化关系
     *
     * @param remoteSocialBo 社会化关系业务对象
     */
    @PostMapping("/save")
    public R<Void> saveSocial(@RequestBody RemoteSocialBo remoteSocialBo) {
        sysSocialService.insertByBo(MapstructUtils.convert(remoteSocialBo, SysSocialBo.class));
        return R.ok();
    }

    /**
     * 更新社会化关系
     *
     * @param remoteSocialBo 社会化关系业务对象
     */
    @PostMapping("/update")
    public R<Void> updateSocial(@RequestBody RemoteSocialBo remoteSocialBo) {
        sysSocialService.updateByBo(MapstructUtils.convert(remoteSocialBo, SysSocialBo.class));
        return R.ok();
    }

    /**
     * 删除社会化关系
     *
     * @param socialId 社会化关系ID
     * @return 结果
     */
    @DeleteMapping("/del/{socialId}")
    public R<Boolean> delSocialById(@PathVariable("socialId") Long socialId) {
        return R.ok(sysSocialService.deleteWithValidById(socialId));
    }

}
